/*
*Copyright 2021-2023 NERCIS
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/

package cn.ac.nercis.pes.model.bo.excel.asset;

import cn.ac.nercis.pes.common.constant.common.AssetConstants;
import cn.ac.nercis.pes.model.dto.evaluation.asset.ServerStorageDTO;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.*;
import org.apache.commons.lang3.StringUtils;

/**
 * 服务器/存储设备资产信息类（导出/导入）
 * @author zpy
 * @version 1.0.0
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class ServerStorageBO extends BaseExcelBO {

    @ExcelProperty(value = "*设备名称",order = 1)
    private String name;
    @ExcelProperty(value = "生产厂商",order = 2)
    private String vendor;
    @ExcelProperty(value = "型号",order = 3)
    private String model;
    @ExcelProperty(value = "操作系统版本",order = 4)
    private String osName;
    @ExcelProperty(value = "是否为虚拟设备",order = 5)
    private String virtual;
    @ExcelProperty(value = "用途",order = 6)
    private String use;
    @ExcelProperty(value = "*数量",order = 7)
    private String count;
    @ExcelProperty(value = "*重要程度",order = 8)
    private String importance;
    @ExcelProperty(value = "是否测评",order = 9)
    private String isUse;
    @ExcelProperty(value = "备注",order = 10)
    private String desc;

    @ExcelIgnore
    private ServerStorageDTO source;

    public boolean isEmpty(){
        return StringUtils.isAllBlank(name,vendor,model,osName,virtual,use,count,importance,isUse,desc);
    }

    public boolean validRequired(){
        return !StringUtils.isAnyBlank(name,count,importance);
    }

    public boolean equalsDTO(@NonNull ServerStorageDTO dto){
        boolean isUse = true;
        if(StringUtils.isNotBlank(this.isUse)){
            isUse = StringUtils.equals(this.isUse, AssetConstants.USE_TAG);
        }
        return StringUtils.equals(name,dto.getName())
                && StringUtils.equals(vendor,dto.getVendor())
                && StringUtils.equals(model,dto.getModel())
                && StringUtils.equals(osName,dto.getOsName())
                && StringUtils.equals(virtual,dto.getVirtual())
                && StringUtils.equals(use,dto.getUse())
                && StringUtils.equals(count,dto.getCount())
                && StringUtils.equals(importance,dto.getImportance())
                && (isUse == dto.getIsUse())
                && StringUtils.equals(desc,dto.getDesc());
    }
}